﻿/*
#**************************************************************************
#  openSIS is a student information system for public and non-public 
#  schools from Open Solutions for Education, Inc. web: www.os4ed.com
#
#  openSIS is  web-based, open source, and comes packed with features that 
#  include student demographic info, scheduling, grade book, attendance, 
#  report cards, eligibility, transcripts, parent portal, 
#  student portal and more.   
#
#  Visit the openSIS web site at http://www.opensis.com to learn more.
#  If you have question regarding this system or the license, please send 
#  an email to info@os4ed.com.
#
#  This program is released under the terms of the GNU General Public License  
#  as  published by the Free Software Foundation, version 2 of the License. 
#  See license.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#**************************************************************************** 

*/

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using OSISStudentSetupDataLayer;
using OSISViewFormLayoutDataLayer;
using OSISDynamicTranslation;

/// <summary>
/// Summary description for ViewFormLayoutBL
/// </summary>
/// 
namespace OSISViewFormLayoutBusinessLayer
{
    public class ViewFormLayoutBL
    {
        DynamicTranslation DTL = new DynamicTranslation();

        private string LanguageToolStSet;
        private int schoolid;
        private int categoryid;
        private int fieldid;
        private static string langto;
        public ViewFormLayoutBL()
        {
            schoolid = 0;
            categoryid = 0;
            fieldid = 0;
            LanguageToolStSet = "";
        }

        public string LangTool
        {
            get
            {
                return this.LanguageToolStSet;
            }
            set
            {
                this.LanguageToolStSet = value;
            }
        }
        public int SchoolId
        {
            get
            {
                return this.schoolid;
            }
            set
            {
                this.schoolid = value;
            }
        }

        public int CategoryId
        {
            get
            {
                return this.categoryid;
            }
            set
            {
                this.categoryid = value;
            }
        }

        public int FieldId
        {
            get
            {
                return this.fieldid;
            }
            set
            {
                this.fieldid = value;
            }
        }

        public System.Data.DataTable GetFieldsByCategory()
        {

            ViewFormLayoutDL StInfoView = new ViewFormLayoutDL();
            DataTable dt = StInfoView.getfieldsbycategory(this);



            DynamicTranslation DTL = new DynamicTranslation();
          //  langto = System.Web.HttpContext.Current.Session["MLUICulture"].ToString();


            if (LangTool != "en")
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string origtext = dt.Rows[i]["FieldName"].ToString();

                    string trantext = DTL.Translate(origtext, "en", langto);
                    dt.Rows[i]["FieldName"] = trantext;
                }
            }


            return dt;
        }
        public System.Data.DataTable GetAddressFieldsByFieldId()
        {

            ViewFormLayoutDL stdl = new ViewFormLayoutDL();
            DataTable dt = stdl.getaddressfieldsbyfieldid(this);


            DynamicTranslation DTL = new DynamicTranslation();
           // langto = System.Web.HttpContext.Current.Session["MLUICulture"].ToString();

            if (LangTool != "en")
            {

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string origtext = dt.Rows[i]["FieldName"].ToString();

                    string trantext = DTL.Translate(origtext, "en", langto);
                    dt.Rows[i]["FieldName"] = trantext;
                }
            }


            return dt;
        }
        public System.Data.DataTable GetAdditionalContactFields()
        {

            ViewFormLayoutDL stdl = new ViewFormLayoutDL();
            DataTable dt = stdl.getadditionalcontactfields(this);

            DynamicTranslation DTL = new DynamicTranslation();
            //langto = System.Web.HttpContext.Current.Session["MLUICulture"].ToString();


            if (LangTool != "en")
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string origtext = dt.Rows[i]["FieldName"].ToString();

                    string trantext = DTL.Translate(origtext, "en", langto);
                    dt.Rows[i]["FieldName"] = trantext;
                }
            }



            return dt;
        }
        public void populatedynamicrchk(ref System.Web.UI.WebControls.CheckBoxList chk)
        {
            ViewFormLayoutDL vmlDL = new ViewFormLayoutDL();
            chk.Items.Clear();
            DataSet ds = null;
            ds = vmlDL.Populatedynamiccontrols(this);
            chk.DataSource = ds.Tables[0];
            chk.DataTextField = "ListItem_name";
            chk.DataValueField = "ListItem_Id";



            chk.DataBind();


        }
        public void populatedynamicrbtn(ref System.Web.UI.WebControls.RadioButtonList rbtn)
        {
            ViewFormLayoutDL vmlDL = new ViewFormLayoutDL();
            rbtn.Items.Clear();
            DataSet ds = null;
            ds = vmlDL.Populatedynamiccontrols(this);
            rbtn.DataSource = ds.Tables[0];
            rbtn.DataTextField = "ListItem_name";
            rbtn.DataValueField = "ListItem_Id";



            rbtn.DataBind();


        }
        public void populatedynamicddl(ref System.Web.UI.WebControls.DropDownList ddl)
        {
            ViewFormLayoutDL vmlDL = new ViewFormLayoutDL();
            ddl.Items.Clear();
            DataSet ds = null;
            ds = vmlDL.Populatedynamiccontrols(this);
            ddl.DataSource = ds.Tables[0];
            ddl.DataTextField = "ListItem_name";
            ddl.DataValueField = "ListItem_Id";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("Select", "0"));

        }
        public void PopulateGender(ref System.Web.UI.WebControls.RadioButtonList rdb)
        {
            ViewFormLayoutDL vmlDL = new ViewFormLayoutDL();
            rdb.Items.Clear();
            DataSet ds = null;
            ds = vmlDL.populategender();


            DynamicTranslation DTL = new DynamicTranslation();
            langto = System.Web.HttpContext.Current.Session["MLUICulture"].ToString();

            if (System.Web.HttpContext.Current.Session["MLUICulture"].ToString() != "en")
            {

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string origtext = ds.Tables[0].Rows[i]["gender_nm"].ToString();

                    string trantext = DTL.Translate(origtext, "en", langto);
                    ds.Tables[0].Rows[i]["gender_nm"] = trantext;
                }
            }



            rdb.DataSource = ds.Tables[0];



            rdb.DataTextField = "gender_nm";
            rdb.DataValueField = "gender_id";
            rdb.DataBind();
            

        }
        public void populateEthnicity(ref System.Web.UI.WebControls.DropDownList ddl)
        {
            ViewFormLayoutDL vmlDL = new ViewFormLayoutDL();
            ddl.Items.Clear();
            DataSet ds = null;
            ds = vmlDL.PopulateEthnicity();

            DynamicTranslation DTL = new DynamicTranslation();
            langto = System.Web.HttpContext.Current.Session["MLUICulture"].ToString();

            if (System.Web.HttpContext.Current.Session["MLUICulture"].ToString() != "en")
            {

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string origtext = ds.Tables[0].Rows[i]["eth_nm"].ToString();

                    string trantext = DTL.Translate(origtext, "en", langto);
                    ds.Tables[0].Rows[i]["eth_nm"] = trantext;
                }

            }

            ddl.DataSource = ds.Tables[0];
            ddl.DataTextField = "eth_nm";
            ddl.DataValueField = "eth_id";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("Select", "0"));


        }
        
        public void populateLanguage(ref System.Web.UI.WebControls.DropDownList ddl)
        {
            ViewFormLayoutDL vmlDL = new ViewFormLayoutDL();
            ddl.Items.Clear();
            DataSet ds = null;
            ds = vmlDL.PopulateLanguage();
            ddl.DataSource = ds.Tables[0];
            ddl.DataTextField = "language_nm";
            ddl.DataValueField = "language_id";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("Select", "0"));

        }

        public void populateState(ref System.Web.UI.WebControls.DropDownList ddl)
        {
            ViewFormLayoutDL vmlDL = new ViewFormLayoutDL();
            ddl.Items.Clear();
            DataSet ds = null;
            ds = vmlDL.PopulateState();
            ddl.DataSource = ds.Tables[0];
            ddl.DataTextField = "NAME";
            ddl.DataValueField = "IID";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("Select", "0"));

        }
        public void populateCountry(ref System.Web.UI.WebControls.DropDownList ddl)
        {
            ViewFormLayoutDL vmlDL = new ViewFormLayoutDL();
            ddl.Items.Clear();
            DataSet ds = null;
            ds = vmlDL.PopulateCountry();
            ddl.DataSource = ds.Tables[0];
            ddl.DataTextField = "NAME";
            ddl.DataValueField = "IID";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("Select", "0"));

        }
        public void PopulateEnrollCdn(ref System.Web.UI.WebControls.DropDownList ddl)
        {
            ViewFormLayoutDL vmlDL = new ViewFormLayoutDL();
            ddl.Items.Clear();
            DataSet ds = null;
            ds = vmlDL.populatrenrollmentcdn();
            ddl.DataSource = ds.Tables[0];
            ddl.DataTextField = "enr_cd_nm";
            ddl.DataValueField = "enr_cd_id";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("Select", "0"));

        }

        public System.Data.DataTable GetSummaryFields()
        {

            ViewFormLayoutDL StInfoView = new ViewFormLayoutDL();
            DataTable dt = StInfoView.getsummaryfields(this);
            return dt;
        }
    }
}
